package com.jinzhi.jzapi.certificate.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.common.utils.ApiResult;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzweb.domain.InformationBatchDO;
import com.jinzhi.jzweb.service.InformationBatchService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * 
 * <pre>
 * 认证批次
 * </pre>
 * <small> 2024-06-06 14:58:39 | Long</small>
 */
@Controller
@RequestMapping("/jzApi/informationBatch")
public class ApiInformationBatchController extends BaseController {
	@Autowired
	private InformationBatchService informationBatchService;

	/**
	 * api小程序端-认证批次证书详情--公开方法，不需要登录
	 *
	 * @Description: 根据认证批次id查询认证批次详情信息，参数：认证批次id
	 * 可以有多个list
	 * @Param: [id]
	 * @return: com.jinzhi.common.utils.ApiResult<?>
	 * @Author: kl
	 * @Date: 2020-03-03
	 */
	@GetMapping("/selInformationBatchs")
	@Log("api小程序端-申报职业")
	@ApiOperation(value = "api小程序端-申报职业", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@Transactional
	@ResponseBody
	public ApiResult<?> selCertificateDetails() {
		Date nowDate = new Date();
		EntityWrapper<InformationBatchDO> wrapper = new EntityWrapper<InformationBatchDO>();
		wrapper.le("start_time",nowDate);
		wrapper.ge("end_time",nowDate);
		List<InformationBatchDO> certificationBatchDOS = informationBatchService.selectList(wrapper);

		if(certificationBatchDOS.isEmpty()){
			return ApiResult.fail("暂无报名批次");
		}

		Map<String, Object> map1 = new HashMap<>();
		List<Map<String, Object>> list = new ArrayList<>();
		certificationBatchDOS.forEach(e->{
			Map<String, Object> map = new HashMap<>();
			map.put("authentication_id",e.getId());
			map.put("certificateName",e.getProfileName());
			map.put("introduce",e.getIntroduce());
			map.put("startTime",e.getStartTime());
			map.put("endTime",e.getEndTime());
			map.put("open_time",e.getOpenTime());
			list.add(map);
		});
		map1.put("list", list);
		return ApiResult.success(map1);
	}
	
}
